# Maintainer: Felix Yan <felixonmars@archlinux.org>
# Contributor: Justin Kromlinger <hashworks@archlinux.org>
# Contributor: Ales Katona <almindor@gmail.com>

pkgname=etherwall
pkgver=3.0.5
# https://github.com/almindor/etherwall/tree/v3.0.5/src
_ewnodecommit=dcc3d76f833a9be47a094e46a0ffa7503e28d007
# https://github.com/almindor/etherwall/tree/v3.0.5/src/trezor
_trezorcommit=db106e8f2766155bc72802e4dc3f9f59c90d9c3e
pkgrel=1
pkgdesc="Ethereum GUI Wallet (QT5)"
arch=('loong64' 'x86_64')
url="https://etherwall.com"
license=('GPL3')
depends=('qt5-declarative' 'qt5-graphicaleffects' 'qt5-quickcontrols' 'qt5-quickcontrols2' 'qt5-websockets' 'geth' 'protobuf' 'libhidapi-libusb.so' 'libusb' 'systemd-libs')
makedepends=('hidapi')
source=("$pkgname-$pkgver.tar.gz::https://github.com/almindor/${pkgname}/archive/v$pkgver.tar.gz"
        "ew-node-$_ewnodecommit.tar.gz::https://github.com/almindor/ew-node/archive/$_ewnodecommit.tar.gz"
        "trezor-common-$_trezorcommit.tar.gz::https://github.com/trezor/trezor-common/archive/$_trezorcommit.tar.gz"
        etherwall.desktop)
sha512sums=('6304d41ac0bec09961cdb5d1467e93c33cad89392ee451bfa92578a05d44fb10450b1392d77ce2be78253e3fcba1bee766593d66440b1b5e15bc97495134d418'
            '3c000ac3ed51406b3038592624135ddc5298ecfccc4523b3d343cb4b3a0f0d74a90ee8b2ef76b00af5ee5a056fed1042fe47067d36daad032bb95a1abf19fdfd'
            '745044fe0686c4f2843a67440e3be8501d8c1d5b8b7275fad7310cfd1110d5cc00378ba4205bed6f5926636a65aa986448594fc6fe276b9f46c902c642ad0373'
            '82ecee1f1d7a6fe7014b928e3ab79ed507c3c5795ac3e832e0be1aca8fc5659212c5a4323d5dec4571b9e9255c5c46615bd9865dc03eba85d8be9b969b534d57')

build() {
  cd "etherwall-$pkgver"
  rmdir "src/ew-node"
  ln -s "../../ew-node-$_ewnodecommit" "src/ew-node"

  SRCDIR="../trezor-common-$_trezorcommit/protob" ./generate_protobuf.sh
  qmake -config release && make
}

package() {
  mkdir -p "$pkgdir/usr/bin"
  mkdir -p "$pkgdir/usr/share/pixmaps"
  mkdir -p "$pkgdir/usr/share/applications"

  cd "etherwall-$pkgver"
  cp "$srcdir"/etherwall.desktop "$pkgdir"/usr/share/applications
  cp "./Etherwall" "$pkgdir"/usr/bin/etherwall
  cp "./qml/images/icon.png" "$pkgdir"/usr/share/pixmaps/etherwall.png
}
